package net.wofly.sale.order.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.wofly.flow.dto.FormPropertyDto;
import net.wofly.sale.activity.domain.ActivityGift;
import org.activiti.engine.task.Comment;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.List;

/**
 * 订单
 *
 * @author lign
 * @version 1.0
 * @created 26-11月-2017 11:32:50
 */
@Data
@Entity(name = "saleOrder")
@Table(name = "sale_order_order")
@ApiModel(description = "订单")
public class Order {
    
    @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinColumn(name = "orderID")
    @ApiModelProperty(value = "介绍人信息", required = true)
    public Introducer introducer;
    
    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinColumn(name = "orderID")
    @ApiModelProperty(value = "订单内容，商品清单", required = true)
    public List<OrderContent> orderContents;
    
    @ApiModelProperty(value = "赠品(订单提交之后)")
    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
    @JoinColumn(name = "relateID")
    public List<Gift> gifts;
    
    @ApiModelProperty(value = "收货地址", required = false)
//    @OneToOne(cascade = CascadeType.MERGE, mappedBy="order")
//    @OneToOne(cascade=CascadeType.ALL,mappedBy="order")
    @Transient
    public OrderReceivingAddr orderReceivingAddr;
    
    @ApiModelProperty(value = "提货门店", required = true)
//    @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
//    @JoinColumn(name = "orderID")
    @Transient
    public TakeGoodsShopInfo takeGoodsShopInfo;
    
    @ApiModelProperty(value = "活动赠品（前端提交订单之前的赠品对象，给前端展示用）")
    @Transient
    private List<ActivityGift> activityGifts;
    
    @Id
    private String orderID;
    /**
     * 活动商品总价/应收
     * <ul>
     * <li>应用活动后，所有商品汇总的活动价格</li>
     * </ul>
     */
    @ApiModelProperty(value = "活动商品总价/应收")
    private Double activityAmount;//活动价格，即打完折扣后的价格  --> 应收
    /**
     * 商品总价
     */
    @ApiModelProperty(value = "商品总价")
    private Double amount; //所有商品总价
    /**
     * 订单优惠价
     * <ul>
     * <li>等于商品总价-活动总价</li>
     * <li></li>
     * </ul>
     */
    @ApiModelProperty(value = "订单优惠价")
    private Double orderDiscounts;//等于商品总价-活动总价
    /**
     * 支付优惠
     * <ul>
     * <li>在支付时实收与活动价之间差价。</li>
     * <li></li>
     * </ul>
     */
    @ApiModelProperty(value = "支付优惠")
    private Double payDiscounts = 0.0;// 优惠价格，销售员可以手动输入
    /**
     * 实收
     * <ul>
     * <li>=活动价-支付优惠</li>
     * </ul>
     */
    @ApiModelProperty(value = "实收", required = true)
    private Double realPrice;
    /**
     * 下单人  谁下单的记录谁
     * <ul>
     * <li>如果是客户自己下单则为客户ID，如果是销售代客下单，则为销售ID</li>
     * </ul>
     */
    @ApiModelProperty(value = "下单人", required = true)
    private String buyer;
    @Transient
    @ApiModelProperty(value = "下单人姓名")
    private String buyerName;
    /**
     * 购买商品的数量
     */
    @ApiModelProperty(value = "购买商品的数量", required = true)
    private Integer commodityNum;
    /**
     * 商品总数
     */
    private Integer commodityTotalNum;
    /**
     * 订单所属客户
     */
    @ApiModelProperty(value = "订单所属客户", required = true)
    private String customerUserID;
    @Transient
    private String customerUserName;
    /**
     * 赠品数量
     * <ul>
     * <li></li>
     * </ul>
     */
    @ApiModelProperty(value = "赠品数量")
    private Integer giftNum;
    /**
     * 订单提交时间
     */
    @ApiModelProperty(value = "订单提交时间")
    private Long orderCommitTime;
    
    /**
     * 订单完成时间
     */
    @ApiModelProperty(value = "订单完成时间")
    private Long finishedTime;
    
    /**
     * 订单类型
     */
    @ApiModelProperty(value = "订单类型（1:会员订单；  2:团购订单；  3:流通订单； 4:酒店订单； 5:签单订单； 6:宴会订单；  7:订货会订单(流通);8:订货会订单(酒店);" +
            "9:还货订单;10:无款订单）", allowableValues = "1,2,3,4,5,6,7,8,9", required = true)
    private Integer orderType;
    @Transient
    private String orderTypeStr;
    /**
     * 出库时间
     */
    @ApiModelProperty(value = "出库时间")
    private Long outStockTime;
    
    /**
     * 订单付款时间
     */
    @ApiModelProperty(value = "订单付款时间")
    private Long payTime;
    /**
     * 下单类型
     * <ul>
     * <li>客户自己下单为自助下单 1</li>
     * <li>销售代为下单为代客下单 2</li>
     * </ul>
     */
    @ApiModelProperty(value = "下单类型(1: 自助下单； 2：代客下单)", required = true, allowableValues = "1,2")
    private Integer placeOrderType;
    @Transient
    private String placeOrderTypeStr;
    
    /**
     * 收货时间
     */
    @ApiModelProperty(value = "收货时间", required = true)
    private Long receiveTime;
    /**
     * 发货时间
     */
    @ApiModelProperty(value = "发货时间", required = true)
    private Long sendTime;
    
    @ApiModelProperty(value = "货物运输类型 1=送货上门 ；2=门店自取", required = true, allowableValues = "1,2")
    private Integer goodTransportType;
    
    @ApiModelProperty(value = "订单支付失效时间")
    private Long payDeadline;
    
    @ApiModelProperty(value = "订单状态")
    private Integer status;
    
    @Transient
    private String statusStr;
    
    @ApiModelProperty(value = "工作流定义key")
    private String processDefKey;
    
    @ApiModelProperty(value = "工作流实例ID")
    private String processInsID;
    
    @ApiModelProperty(value = "工作流任务ID")
    private String taskID;
    
    @ApiModelProperty(value = "工作流任务名称")
    private String taskName;
    
    @ApiModelProperty(value = "工作流任务代理人")
    private String taskAssignee;
    
    @ApiModelProperty(value = "工作流实例审批意见")
    @Transient
    private List<Comment> comments;
    
    @ApiModelProperty(value = "任务表单内容")
    @Transient
    private List<FormPropertyDto> formPropertyDtos;
    
    @Transient
    private PayInfo payInfo;
    
    @Transient
    @ApiModelProperty(value = "订单的剩余支付时间")
    private Long payRestTime;
    
    @Transient
    @ApiModelProperty(value = "收货地址或者提货门店，查询接口返回时用")
    private String addrStr;
    
    private String orderNo;
    
    @ApiModelProperty(value = "订单备注")
    private String descp;
    
    @ApiModelProperty(value = "支付凭证URL")
    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
    @JoinColumn(name = "orderID")
    private List<PayInfoPic> payInfoPics;
    
    @Transient
    @ApiModelProperty(value = "支付方式（支付类型）")
    private Integer payType;
    
    @Transient
    @ApiModelProperty(value = "付款金额，定金支付时会用")
    private BigDecimal payAmount;
    
    /**
     * 销售员（业务员ID）
     */
    private String salerID;
    
    public Order() {
    
    }
    
    @Override
    public void finalize() throws Throwable {
    
    }
}